Page({
    data: {
        totalHousePayment: "",
        repaymentDetail: [],
        topShow: "none",
        previewHidden: !0
    },
    bindGoBack: function(e) {
        wx.switchTab({
            url: "/pages/index/index"
        });
    },
    onPageScroll: function(e) {
        e.scrollTop > 600 ? (console.log("> 600"), this.setData({
            topShow: "block"
        })) : (console.log("< 600"), this.setData({
            topShow: "none"
        }));
    },
    goTop: function(e) {
        wx.pageScrollTo ? wx.pageScrollTo({
            scrollTop: 0
        }) : wx.showModal({
            title: "提示",
            content: "当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。"
        });
    },
    bindReward: function(e) {
        wx.previewImage({
            current: [ "http://m.qpic.cn/psb?/dbf33b4b-8686-4aef-8e55-daa297472874/VqJjsbF5iHISydc0QP83e3Ece9cDJdTuKG4ISs*OUSU!/b/dC4BAAAAAAAA&bo=OAQ4BAAAAAARBzA!&rf=viewer_4" ],
            urls: [ "http://m.qpic.cn/psb?/dbf33b4b-8686-4aef-8e55-daa297472874/VqJjsbF5iHISydc0QP83e3Ece9cDJdTuKG4ISs*OUSU!/b/dC4BAAAAAAAA&bo=OAQ4BAAAAAARBzA!&rf=viewer_4" ]
        });
    },
    onLoad: function(e) {
        var t = this, a = new Promise(function(e, t) {
            wx.getImageInfo({
                src: "../../images/bg3.jpg",
                success: function(t) {
                    console.log(t), e(t);
                }
            });
        }), n = "none", o = "none";
        "1" == e.repaymentType ? (n = "block", o = "none") : (n = "none", o = "block");
        var s = [], i = [], l = [];
        if (console.log("e.firstRepayment1", e.firstRepayment, "e.decrease", e.decrease, "e.loanMonths", e.loanMonths, "e.loanType", e.loanType), 
        "undefined" != e.firstRepayment && "undefined" != e.decrease && "undefined" != e.loanMonths && 0 == e.loanType || 1 == e.loanType) {
            for (var r = 0; r < Number(e.loanMonths); r++) s.push(Number(Number(e.firstRepayment) - Number(e.decrease) * r).toFixed(2));
            console.log(s, "555");
        }
        if (console.log("e.firstRepaymentsy2", e.firstRepaymentsy, "e.decreasesy", e.decreasesy, "e.firstRepaymentgjj", e.firstRepaymentgjj, "e.decreasegjj", e.decreasegjj, "e.loanMonths", e.loanMonths, "e.loanType", e.loanType), 
        "undefined" != e.firstRepaymentsy && "undefined" != e.decreasesy && "undefined" != e.firstRepaymentgjj && "undefined" != e.decreasegjj && "undefined" != e.loanMonths && 2 == e.loanType) {
            for (var c = 0; c < Number(e.loanMonths); c++) i.push(Number(Number(e.firstRepaymentsy) - Number(e.decreasesy) * c));
            for (var d = 0; d < Number(e.loanMonths); d++) l.push(Number(Number(e.firstRepaymentgjj) - Number(e.decreasegjj) * d));
            for (var m = 0; m < e.loanMonths; m++) s.push(Number(Number(l[m]) + Number(i[m])).toFixed(2));
            console.log(s, "6666");
        }
        this.setData({
            totalHousePayment: e.totalHousePayment ? Number(e.totalHousePayment).toFixed(2) : "/",
            totalLoanCeiling: Number(e.totalLoanCeiling).toFixed(2),
            loanMonths: e.loanMonths,
            monthlyRepayment: Number(e.monthlyRepayment).toFixed(2),
            initialPayment: e.initialPayment ? Number(e.initialPayment).toFixed(2) : "/",
            totalRepayment: Number(e.totalRepayment).toFixed(2),
            interest: Number(e.interest).toFixed(2),
            show: n,
            show1: o,
            firstRepayment: e.firstRepayment ? Number(e.firstRepayment).toFixed(0) : "",
            repaymentDetail: s
        }), Promise.all([ a ]).then(function(e) {
            console.log(e);
            var a = wx.createCanvasContext("shareImg");
            n = 0 == s[0] ? 260 : 25 * s.length + 260, a.drawImage("../../" + e[0].path, 0, 0, 375, n), 
            a.setFillStyle("#ffffff"), a.setFontSize(18);
            var n;
            if (0 == s[0]) n = 260, t.setData({
                h: n
            }), a.fillText("月均还款：" + t.data.monthlyRepayment + "元", 60, 220); else {
                n = 25 * s.length + 260, t.setData({
                    h: n
                }), a.fillText("月还明细：", 60, 220);
                for (var o = 0; o < s.length; o++) {
                    var i = o + 1, l = o + 7;
                    a.fillText("第" + i + "月还款额: " + s[o] + "元", 90, 70 + 25 * l);
                }
            }
            a.fillText("房款总额：" + t.data.totalHousePayment + "元", 60, 70), a.fillText("贷款总额：" + t.data.totalLoanCeiling + "元", 60, 95), 
            a.fillText("还款总额：" + t.data.totalRepayment + "元", 60, 120), a.fillText("支付利息：" + t.data.interest + "元", 60, 145), 
            a.fillText("首期付款：" + t.data.initialPayment + "元", 60, 170), a.fillText("贷款月数：" + t.data.loanMonths + "月", 60, 195), 
            a.stroke(), a.draw();
        });
    },
    share: function() {
        var e = this;
        e.setData({
            pageCss: "position:fixed"
        }), wx.showLoading({
            title: "努力生成中..."
        }), wx.canvasToTempFilePath({
            x: 0,
            y: 0,
            width: 375,
            height: this.data.h,
            destWidth: 375,
            destHeight: this.data.h,
            canvasId: "shareImg",
            success: function(t) {
                console.log(t), console.log(t.tempFilePath), e.setData({
                    preurl: t.tempFilePath,
                    previewHidden: !1
                }), wx.hideLoading();
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    save: function() {
        var e = this;
        wx.getSetting({
            success: function(t) {
                t.authSetting["scope.writePhotosAlbum"] ? e.startSaveImage() : wx.authorize({
                    scope: "scope.writePhotosAlbum",
                    success: function() {
                        e.startSaveImage();
                    }
                });
            }
        });
    },
    startSaveImage: function() {
        var e = this;
        wx.saveImageToPhotosAlbum({
            filePath: e.data.preurl,
            success: function(t) {
                wx.showModal({
                    content: "图片已保存到相册，赶紧晒一下吧~",
                    showCancel: !1,
                    confirmText: "好哒",
                    confirmColor: "#72B9C3",
                    success: function(t) {
                        t.confirm && (console.log("用户点击确定"), e.setData({
                            previewHidden: !0
                        }));
                    }
                });
            }
        });
    },
    closeSave: function() {
        this.setData({
            previewHidden: !0,
            pageCss: ""
        });
    }
});